home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_539 / pf / source / wb.c < prev   
C/C++ Source or Header  |  1992-05-06  |  10KB  |  417 lines

  1. /*---------------------------------------------------------*
  2.  | Author:  Maurizio Loreti, aka MLO or I3NOO.             |
  3.  | Address: University of Padova - Department of Physics   |
  4.  |          Via F. Marzolo, 8 - 35131 PADOVA - Italy       |
  5.  | Phone:   (39)(49) 844-313         FAX: (39)(49) 844-245 |
  6.  | E-Mail:  LORETI at IPDINFN (BITNET); or VAXFPD::LORETI  |
  7.  |         (DECnet) - VAXFPD is node 38.257 i.e. 39169; or |
  8.  |          LORETI@PADOVA.INFN.IT (INTERNET).              |
  9.  | Home: Via G. Donizetti 6 - 35010 CADONEGHE (PD) - Italy |
  10.  *---------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <stdarg.h>
  15. #include <stdlib.h>
  16. #include <exec/types.h>
  17. #include <intuition/intuition.h>
  18. #include <graphics/gfxbase.h>
  19. #include <libraries/dos.h>
  20. #include <libraries/reqbase.h>
  21. #include <devices/printer.h>
  22. #include "mlo.h"
  23. #include "pf2.h"
  24. #include "ext.h"
  25. #include "aw.h"
  26.  
  27. struct IntuiMessage *GetMsg();
  28. struct Window       *OpenWindow();
  29.  
  30. void SetupWB(void)
  31. {
  32.  
  33. /**
  34.  | Printer setup, driven with requester windows when called from
  35.  | the Workbench.
  36. **/
  37.  
  38.   struct GetLongStruct GLS = {
  39.     NULL, 0, 0, 0, 0, NULL, REQVERSION, 0, 0
  40.   };
  41.  
  42.   char  cOri[] = "Orientation";
  43.   char *tOri[] = {
  44.     "Portrait",
  45.     "Landscape",
  46.     "\"Special\""
  47.   };
  48.   #define nOri (sizeof(tOri) / sizeof(char *))
  49.  
  50.   char  cFon[] = "Font";
  51.   char *tFon[] = {
  52.     "Courier",
  53.     "Letter-Gothic",
  54.     "Times"
  55.   };
  56.   #define nFon (sizeof(tFon) / sizeof(char *))
  57.  
  58.   char  cPit[]  = "Horizontal pitch";
  59.   char *tPitC[] = {
  60.     "10 characters per inch",
  61.     "16.67 characters per inch",
  62.     "20 characters per inch"
  63.   };
  64.   char *tPitG[] = {
  65.     "12 characters per inch",
  66.     "24 characters per inch"
  67.   };
  68.   #define nPitC (sizeof(tPitC) / sizeof(char *))
  69.   #define nPitG (sizeof(tPitG) / sizeof(char *))
  70.  
  71.   char  cSty[] = "Style";
  72.   char *tSty[] = {
  73.     "Roman",
  74.     "Italic"
  75.   };
  76.   #define nSty (sizeof(tSty) / sizeof(char *))
  77.  
  78.   char  cHei[] = "Character height";
  79.   char *tHei[] = {
  80.     "12 points",
  81.     "6 points"
  82.   };
  83.   #define nHei (sizeof(tHei) / sizeof(char *))
  84.  
  85.   char  cQua[] = "Quality";
  86.   char *tQua[] = {
  87.     "Draft",
  88.     "Letter"
  89.   };
  90.   #define nQua (sizeof(tQua) / sizeof(char *))
  91.  
  92.   char  cSpa[] = "Vertical spacing";
  93.   char *tSpa[] = {
  94.     "6 lines per inch",
  95.     "8 lines per inch"
  96.   };
  97.   #define nSpa (sizeof(tSpa) / sizeof(char *))
  98.  
  99. /**
  100.  | Open required libraries
  101. **/
  102.  
  103.   GfxBase       = LibOpen("graphics.library",   REVISION);
  104.   ReqBase       = LibOpen("req.library",        0);
  105.  
  106. r1:
  107.   switch (Ask(cOri, nOri, tOri)) {
  108.     case QUIT:
  109.     case CANCEL:
  110.       Cleanup(SYS_NORMAL_CODE);
  111.     case 1:
  112.       PageMode = SINGLE_PAGE;
  113.       Orientation = PORTRAIT;
  114. r2:   switch (Ask(cFon, nFon, tFon)) {
  115.         case QUIT:
  116.           Cleanup(SYS_NORMAL_CODE);
  117.         case CANCEL:
  118.           goto r1;
  119.         case 1:
  120.           Font = COURIER;
  121.           switch (Ask(cPit, nPitC, tPitC)) {
  122.             case QUIT:
  123.               Cleanup(SYS_NORMAL_CODE);
  124.             case CANCEL:
  125.               goto r2;
  126.             case 1:
  127.               Pitch = P10CPI;
  128.               break;
  129.             case 2:
  130.               Pitch = P16_67CPI;
  131.               break;
  132.             case 3:
  133.               Pitch = P20CPI;
  134.               break;
  135.           }
  136.           break;
  137.         case 2:
  138.           Font = GOTHIC;
  139.           switch (Ask(cPit, nPitG, tPitG)) {
  140.             case QUIT:
  141.               Cleanup(SYS_NORMAL_CODE);
  142.             case CANCEL:
  143.               goto r2;
  144.             case 1:
  145.               Pitch = P12CPI;
  146.               break;
  147.             case 2:
  148.               Pitch = P24CPI;
  149.           }
  150.           break;
  151.         case 3:
  152.           Font = TIMES;
  153.           Pitch = PROPORTIONAL;
  154.           break;
  155.       }
  156.  
  157.       if (Font == COURIER  &&  Pitch == P16_67CPI) {
  158.         Style = ROMAN;
  159.       } else {
  160.         switch (Ask(cSty, nSty, tSty)) {
  161.           case QUIT:
  162.             Cleanup(SYS_NORMAL_CODE);
  163.           case CANCEL:
  164.             goto r2;
  165.           case 1:
  166.             Style = ROMAN;
  167.             break;
  168.           case 2:
  169.             Style = ITALIC;
  170.             break;
  171.         }
  172.       }
  173.       break;
  174.  
  175.     case 2:
  176. r2l:  Orientation = LANDSCAPE;
  177.       PageMode = SINGLE_PAGE;
  178.       Font = COURIER;
  179.       switch (Ask(cPit, nPitC, tPitC)) {
  180.         case QUIT:
  181.           Cleanup(SYS_NORMAL_CODE);
  182.         case CANCEL:
  183.           goto r1;
  184.         case 1:
  185.           Pitch = P10CPI;
  186.           break;
  187.         case 2:
  188.           Pitch = P16_67CPI;
  189.           break;
  190.         case 3:
  191.           Pitch = P20CPI;
  192.           break;
  193.       }
  194.       break;
  195.     case 3:
  196.       PageMode = LEFT_PAGE;
  197.       goto r5;
  198.   }
  199.  
  200. r3:
  201.   switch (Ask(cHei, nHei, tHei)) {
  202.     case QUIT:
  203.       Cleanup(SYS_NORMAL_CODE);
  204.     case CANCEL:
  205.       if (Orientation == PORTRAIT)  goto r2;
  206.       else                          goto r2l;
  207.     case 1:
  208.       Height = 12;
  209.       break;
  210.     case 2:
  211.       Height = 6;
  212.       break;
  213.   }
  214.  
  215. r4:
  216.   switch (Ask(cSpa, nSpa, tSpa)) {
  217.     case QUIT:
  218.       Cleanup(SYS_NORMAL_CODE);
  219.     case CANCEL:
  220.       goto r3;
  221.     case 1:
  222.       Lpi = 6;
  223.       break;
  224.     case 2:
  225.       Lpi = 8;
  226.       break;
  227.   }
  228.  
  229. r5:
  230.   switch (Ask(cQua, nQua, tQua)) {
  231.     case QUIT:
  232.       Cleanup(SYS_NORMAL_CODE);
  233.     case CANCEL:
  234.       if (PageMode == LEFT_PAGE)   goto r1;
  235.          else                      goto r4;
  236.     case 1:
  237.       Quality = DRAFT_Q;
  238.       break;
  239.     case 2:
  240.       Quality = LETTER_Q;
  241.       break;
  242.   }
  243.  
  244.   windowOff();
  245.   if (PageMode == LEFT_PAGE)    goto r7;
  246.  
  247. r6:
  248.   GLS.titlebar = "Leading blanks:";
  249.   GLS.defaultval = 0;
  250.   GLS.minlimit = 0;
  251.   GLS.maxlimit = 40;
  252.   if (GetLong(&GLS)) {
  253.     nBlanks = GLS.result;
  254.     if (nBlanks) {
  255.       Buffer = inBuffer + nBlanks;
  256.       memset(inBuffer, BLANK, nBlanks);
  257.     }
  258.   } else {
  259.     goto r5;
  260.   }
  261.  
  262. r7:
  263.   GLS.titlebar = "TAB expansion:";
  264.   GLS.defaultval = 8;
  265.   GLS.minlimit = 2;
  266.   GLS.maxlimit = 20;
  267.   if (GetLong(&GLS)) {
  268.     nTabs = GLS.result;
  269.   } else {
  270.     if (PageMode == LEFT_PAGE)    goto r5;
  271.        else                       goto r6;
  272.   }
  273.  
  274.   if (PageMode == LEFT_PAGE)    SetSpecialMode();
  275. }
  276.  
  277. void windowOff(void)
  278. {
  279.   struct IntuiMessage *pIM;
  280.  
  281.   if (Wind != NULL) {
  282.     while ((pIM = GetMsg(Wind->UserPort)) != NULL) ReplyMsg(pIM);
  283.     CloseWindow(Wind);
  284.     Wind = NULL;
  285.   }
  286. }
  287.  
  288. void *LibOpen(
  289.   char *Name,                     /* Library name */
  290.   long  Rev                       /* Revision level (or 0) */
  291. ){
  292.  
  293. /**
  294.  | Open required library
  295. **/
  296.  
  297.   void *p;
  298.  
  299.   p = (void *) OpenLibrary(Name, Rev);
  300.   if (p == NULL) Cleanup(SYS_ABORT_CODE);
  301.   return p;
  302. }
  303.  
  304. int Ask(
  305.   char *pTitle,                   /* General title */
  306.   int nText,                      /* Number of choices */
  307.   char *cText[]                    /* Description */
  308. ){
  309.  
  310. /**
  311.  | This routine displays a "cycle gadget" (an array of nText choices
  312.  | described by cText[]): i.e. a window where the general title and the
  313.  | current choice are displayed, together with a forward- and a backward-
  314.  | cycling gadget, and the 3 fixed gadgets "OK", "QUIT" and "CANCEL".
  315.  | The return value is either CANCEL (0), or QUIT (-1), or, if OK was
  316.  | selected, a number in the range 1..nText identifying the currently
  317.  | selected cycle-gadget choice. The window size should be enough to
  318.  | display the pTitle and cText strings.
  319. **/
  320.  
  321.   int x;                          /* X coordinate, current string */
  322.   int n;                          /* Number of characters, cur. string */
  323.   int newx, newn, newcurrent;
  324.   int current = 0;                /* Current cycle gadget choice */
  325.   struct IntuiMessage *pIM;       /* Intuition message */
  326.   ULONG MClass;                   /* Message type */
  327.   struct RastPort *pRP;           /* Requester window raster port */
  328.   struct Gadget *pG;              /* Selected gadget */
  329.  
  330. /**
  331.  | Ask() uses the same window for all our cycle gadgets; the first
  332.  | time, it has to be opened (will be closed calling windowOff()).
  333. **/
  334.  
  335.   if (Wind == NULL) {
  336.     sprintf(title, "PF2 v%.2f - MLO %d ", VERSION, LAST_CHANGE);
  337.     if ( (Wind = OpenWindow(&NWind)) == NULL) {
  338.       Cleanup(SYS_ABORT_CODE);
  339.     }
  340.     realWidth  = Wind->Width  - Wind->BorderRight;
  341.     realHeight = Wind->Height - Wind->BorderBottom;
  342.   }
  343.  
  344. /**
  345.  | Clear the window, and display the general title and the first
  346.  | cycle-gadget choice.
  347. **/
  348.  
  349.   SetAPen((pRP = Wind->RPort), BLACK_PEN);
  350.   RectFill(pRP, Wind->BorderLeft, Wind->BorderTop,
  351.            realWidth, realHeight);
  352.   RefreshGadgets(askGad, Wind, NULL);
  353.  
  354.   SetAPen(pRP, RED_PEN);
  355.   SetBPen(pRP, BLACK_PEN);
  356.   x = (realWidth - TextLength(pRP, pTitle, (n = strlen(pTitle)))) / 2;
  357.   Move(pRP, x, AW_YTITLE);
  358.   Text(pRP, pTitle, n);
  359.  
  360.   x = (realWidth - TextLength(pRP, cText[0], (n = strlen(cText[0])))) / 2;
  361.   SetAPen(pRP, WHITE_PEN);
  362.   Move(pRP, x, AW_YCYCLE);
  363.   Text(pRP, cText[0], n);
  364.  
  365. /**
  366.  | Now, wait for gadget hits and perform the appropriate action.
  367.  | Exit when either OK or CANCEL or QUIT has been hit.
  368. **/
  369.  
  370.   FOREVER {
  371.     Wait(1 << Wind->UserPort->mp_SigBit);
  372.     while ((pIM = GetMsg(Wind->UserPort)) != NULL) {
  373.       MClass = pIM->Class;
  374.       pG = (struct Gadget *) pIM->IAddress;
  375.       ReplyMsg(pIM);
  376.  
  377.       switch (MClass) {
  378.         case GADGETUP:
  379.  
  380.           switch (pG->GadgetID) {
  381.             case AW_CANCEL:
  382.               return CANCEL;
  383.             case AW_QUIT:
  384.               return QUIT;
  385.             case AW_OK:
  386.               return ++current;
  387.             case AW_FORWARD:
  388.               newcurrent = ++current;
  389.               if (newcurrent >= nText) {
  390.                 newcurrent = 0;
  391.               }
  392.               newx = (realWidth - TextLength(pRP, cText[newcurrent],
  393.                   (newn = strlen(cText[newcurrent])))) / 2;
  394.               break;
  395.             case AW_BACKWARD:
  396.               newcurrent = --current;
  397.               if (newcurrent < 0) newcurrent = nText - 1;
  398.               newx = (realWidth - TextLength(pRP, cText[newcurrent],
  399.                   (newn = strlen(cText[newcurrent])))) / 2;
  400.               break;
  401.           }
  402.  
  403.           SetAPen(pRP, BLACK_PEN);
  404.           Move(pRP, x, AW_YCYCLE);
  405.           Text(pRP, cText[current], n);
  406.           SetAPen(pRP, WHITE_PEN);
  407.  
  408.           current = newcurrent;
  409.           x = newx;
  410.           n = newn;
  411.           Move(pRP, x, AW_YCYCLE);
  412.           Text(pRP, cText[current], n);
  413.       }
  414.     }
  415.   }
  416. }
  417.